//
//  EXT+UIButton.swift
//  BAweibo
//
//  Created by baggio on 2017/8/15.
//  Copyright © 2017年 baggio. All rights reserved.
//

import UIKit

extension UIButton{
    
    convenience init(title:String?,
                     titleColor:UIColor?,
                     titleColorHighlight:UIColor?,
                     titleLabelFont:CGFloat?,
                     imgName:String?,
                     backgroundImgName:String?,
                     target:Any?,
                     action:Selector?) {
        
        self.init()
        
        if let t=title{
            setTitle(t, for: .normal)
        }
        if let tcn=titleColor{
            setTitleColor(tcn, for: .normal)
        }
        if let tch=titleColorHighlight{
            setTitleColor(tch, for: .highlighted)
        }
        if let tlf=titleLabelFont{
            titleLabel?.font=UIFont.systemFont(ofSize: tlf)
        }
        if let i=imgName{
            setImage(UIImage(named:i), for: .normal)
            setImage(UIImage(named:"\(i)_highlighted"), for: .highlighted)
        }
        if let bi=backgroundImgName{
            setBackgroundImage(UIImage(named:bi), for: .normal)
            setBackgroundImage(UIImage(named:"\(bi)_highlighted"), for: .highlighted)
        }
        if let t=target,let a=action{
            addTarget(t, action: a, for: .touchUpInside)
        }
        sizeToFit()
    }
}
